package com.ruoyi.app.controller.common.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.DO.DistrictsDO;
import com.ruoyi.common.entity.VO.DistrictVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IDistrictsMapper extends BaseMapper<DistrictsDO> {

    @Select("SELECT id,pid,name,ext_name extName FROM districts WHERE  pid = 0")
    List<DistrictVO> listDistricts();

    @Select("SELECT id,pid,name,ext_name extName FROM districts WHERE  pid = #{parentId} ")
    List<DistrictVO> listDistrictsByParentId(Long parentId);

    @Select("SELECT ext_name FROM districts WHERE id = #{arg0} ")
    String getName(Integer id);

    @Select("SELECT id FROM districts WHERE ext_name = #{arg0} and deep = 0")
    Integer getProvinceId(String name);

    @Select("SELECT id FROM districts WHERE ext_name = #{arg0} and deep = 1")
    Integer getCityId(String name);

    @Select("SELECT id FROM districts WHERE ext_name = #{zoneName} and deep = 2 and pid=#{cityId}")
    Integer getZoneId(@Param("zoneName") String zoneName,@Param("cityId") Integer cityId);

}
